package org.ssgroup.test;

import java.io.FileOutputStream;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;

import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.ssgroup.util.DBDataUtil;

/**
 * 2017-06-08
 * @author yuruixin
 */
public class DBDataToWord {
	
	public static void main(String[] args) throws Exception {
		XWPFDocument xdoc = new XWPFDocument();
		DBDataToWord xsg_data = new DBDataToWord();
		for(Entry<String,Object> entry : getTables().entrySet()){
			String tableName = entry.getKey();
			String tableName_CN = String.valueOf(entry.getValue());
			DBDataUtil.createTable(xdoc,tableName,tableName_CN);
		}
		xsg_data.saveDocument(xdoc, "d:/" + "xsg" + ".docx");
	}
	
	/**
	 * @Description: 保存文档
	 */
	public void saveDocument(XWPFDocument document, String savePath)
			throws Exception {
		FileOutputStream fos = new FileOutputStream(savePath);
		document.write(fos);
		fos.close();
	}
	
	/**
	 * 这个地方可以优化，直接查询数据库
	 * @return
	 */
	public static Map<String,Object> getTables(){
		Map<String,Object> params = new LinkedHashMap<String,Object>();
		params.put("oa_user", "员工表");
		params.put("lj_oa_amount_setting", "赔偿金额设置表");
		params.put("lj_oa_attendance_edit_info", "请假统计表");
		params.put("lj_oa_calendar", "公司日历详细表");
		params.put("lj_oa_card_apply", "开具证明表");
		params.put("lj_oa_commission", "请假事项表");
		params.put("lj_oa_commission_apply", "请假事项和流程日志中间表");
		params.put("lj_oa_commission_examine", "请假流程主表");
		params.put("lj_oa_commission_switch", "请假开关表");
		params.put("lj_oa_company_calendar", "公司日历表");
		params.put("lj_oa_compensation_apply", "赔偿流程表");
		params.put("lj_oa_content_message", "我的消息表");
		params.put("lj_oa_emolument", "税前工资存储表");
		params.put("lj_oa_emolument_second", "税后工资存储表");
		params.put("lj_oa_flow", "行政流程表");
		params.put("lj_oa_late_config", "考勤设置表");
		params.put("lj_oa_leave", "请假设置表");
		params.put("lj_oa_meetroom_msg", "会议室表");
		params.put("lj_oa_message", "图文消息表");
		params.put("lj_oa_message_status", "消息中间表");
		params.put("lj_oa_operator_log", "操作日志表");
		params.put("lj_oa_organization", "组织机构表");
		params.put("lj_oa_printandcard_apply", "证件和印章审批表");
		params.put("lj_oa_raise_statics", "税筹统计表");
		params.put("lj_oa_raisetaxes", "税筹设置表");
		params.put("lj_oa_region", "地区表");
		params.put("lj_oa_resource", "资料表");
		params.put("lj_oa_resource_status", "资料消息中间表");
		params.put("lj_oa_shift", "班次设定表");
		params.put("lj_oa_sign", "考勤签到签退表");
		params.put("lj_oa_talk", "人事留言版表");
		params.put("lj_oa_work_flow_log", "流程日志表");
		params.put("oa_approval", "审批表");
		params.put("oa_attendance", "考勤表");
		params.put("oa_room_apply", "会议室申请表");
		
		return params;
	}
}
